home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / test / StripXpkStuff.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  3KB  |  116 lines

  1. #define NAME        "StripXpkStuff"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "0"
  4.  
  5. /* NOTE: This program depends on certain things, which may change. It is
  6. only valid as long as the xpkmaster internal structures do not change.
  7. It is only for tests and no standard use tool!!! Never distribute a binary
  8. version of it or use its routines in other programs! */
  9.  
  10. /* Programmheader
  11.  
  12.     Name:        StripXpkStuff
  13.     Author:        SDI
  14.     Distribution:    Freeware
  15.     Description:    strips xpk-headers from XPKF files (for tests only)
  16.     Compileropts:    -
  17.     Linkeropts:    -
  18.  
  19.  1.0   21.02.98 : first Version
  20. */
  21.  
  22. #include <proto/dos.h>
  23. #include <proto/exec.h>
  24. #include <exec/memory.h>
  25. #include "SDI_defines.h"
  26. #include "/xpkmaster/xpkmaster.h"
  27.  
  28. #define PARAM        "FROM/A,TO/A"
  29.  
  30. struct Args {
  31.   STRPTR from;
  32.   STRPTR to;
  33. };
  34.  
  35. void main(void)
  36. {
  37.   struct Args args;
  38.   struct RDArgs *rda;
  39.  
  40.   args.to = 0;
  41.       
  42.   if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  43.   {
  44.     ULONG fh;
  45.  
  46.     if(!args.to)
  47.       args.to = args.from;
  48.  
  49.     if((fh = Open(args.from, MODE_OLDFILE)))
  50.     {
  51.       ULONG size;
  52.  
  53.       if(Read(fh, &size, 4) == 4)
  54.       {
  55.         if(size == 0x58504B46)
  56.         {
  57.           if(Read(fh, &size, 4) == 4)
  58.           {
  59.             STRPTR mem;
  60.             if((mem = (STRPTR) AllocMem(size, MEMF_ANY)))
  61.             {
  62.               if(Read(fh, mem, size) == size)
  63.               {
  64.                 Close(fh);
  65.                 if((fh = Open(args.to, MODE_NEWFILE)))
  66.                 {
  67.                   struct XpkStreamHeader *sh;
  68.             
  69.                   sh = (struct XpkStreamHeader *) (mem-8);
  70.  
  71.           if(!(sh->xsh_Flags & XPKSTREAMF_EXTHEADER))
  72.           {
  73.                     if(sh->xsh_Flags & XPKSTREAMF_LONGHEADERS)
  74.                     {
  75.                       struct XpkChunkHdrLong *ch;
  76.  
  77.                   ch = (struct XpkChunkHdrLong *)
  78.                   (mem+sizeof(struct XpkStreamHeader)-8);
  79.                   while(ch->xchl_Type != XPKCHUNK_END)
  80.                   {
  81.                     Write(fh, ((STRPTR) ch) + sizeof(struct XpkChunkHdrLong),
  82.                     ch->xchl_CLen);
  83.                     ch = (struct XpkChunkHdrLong *) (((STRPTR) ch) +
  84.                     sizeof(struct XpkChunkHdrLong) + ROUNDLONG(ch->xchl_CLen));
  85.                   }
  86.                 }
  87.                 else
  88.                 {
  89.                       struct XpkChunkHdrWord *ch;
  90.  
  91.                   ch = (struct XpkChunkHdrWord *)
  92.                   (mem+sizeof(struct XpkStreamHeader)-8);
  93.                   while(ch->xchw_Type != XPKCHUNK_END)
  94.                   {
  95.                     Write(fh, ((STRPTR) ch) + sizeof(struct XpkChunkHdrWord),
  96.                     ch->xchw_CLen);
  97.                     ch = (struct XpkChunkHdrWord *) (((STRPTR) ch) +
  98.                     sizeof(struct XpkChunkHdrWord) + ROUNDLONG(ch->xchw_CLen));
  99.                   }
  100.                 }
  101.               }
  102.                 }
  103.               }
  104.               FreeMem(mem, size);
  105.             }
  106.           }
  107.         }
  108.       }
  109.       if(fh)
  110.         Close(fh);
  111.     }
  112.     FreeArgs(rda);
  113.   }
  114. }
  115.  
  116.